package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.UserDevice;
import org.apache.ibatis.annotations.*;

public interface UserDeviceMapper {
    @Delete({
        "delete from user_device",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into user_device (id, uid, device_id, ",
        "register_time, login_time)",
        "values (#{id,jdbcType=BIGINT}, #{uid,jdbcType=BIGINT}, #{deviceId,jdbcType=BIGINT}, ",
        "#{registerTime,jdbcType=TIMESTAMP}, #{loginTime,jdbcType=TIMESTAMP})"
    })
    int insert(UserDevice record);

    int insertSelective(UserDevice record);

    @Select({
        "select",
        "id, uid, device_id, register_time, login_time",
        "from user_device",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    UserDevice selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(UserDevice record);

    @Update({
        "update user_device",
        "set uid = #{uid,jdbcType=BIGINT},",
          "device_id = #{deviceId,jdbcType=BIGINT},",
          "register_time = #{registerTime,jdbcType=TIMESTAMP},",
          "login_time = #{loginTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(UserDevice record);

    /***********以下为自定义方法************************/

    @Select({
            "select * ",
            "from user_device",
            "where uid = #{uid,jdbcType=BIGINT} and device_id = #{deviceId,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    UserDevice selectByUidAndDeviceId(@Param("uid")Long uid, @Param("deviceId")Long deviceId);
}